#!/usr/bin/env python
#-------------------------------------------------------------------------------
##	\file nxp_cpp.py
##
##	\brief
##	Get CPP working in the NXP environment.
##
##	The goal is verify that all the calls in a library are called
##	at least once.
##
#	$Id: $
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#	The MIT License (MIT)
#
#	Copyright (c) 2014 A.C. Verbeck
#
#	Permission is hereby granted, free of charge, to any person obtaining a copy
#	of this software and associated documentation files (the "Software"), to deal
#	in the Software without restriction, including without limitation the rights
#	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#	copies of the Software, and to permit persons to whom the Software is
#	furnished to do so, subject to the following conditions:
#
#	The above copyright notice and this permission notice shall be included in
#	all copies or substantial portions of the Software.
#
#	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#	THE SOFTWARE.
#-------------------------------------------------------------------------------
from __future__ import print_function
from pycparser import parse_file
import sys

__author__ = '$Author: $'
__version__ = '$Rev: $'
__date__ = '$Date: $'
__license__ = 'MIT'


#-------------------------------------------------------------------------------
##	file_parse -- parses the translation unit and displays everything
#
##	\brief
##	This function parses the translation unit and displays everything
#
##	\param	opt		options passed from command line
##
#-------------------------------------------------------------------------------
ARGV = ['-E',
	r'-I..\..\..\..\..\..\software\lpc_core\lpc_chip\chip_8xx',
	r'-I..\..\..\..\..\..\software\lpc_core\lpc_chip\chip_8xx\config_82x',
	r'-I..\..\..\..\..\..\software\lpc_core\lpc_chip\chip_common',
	r'-I..\..\..\..\..\..\software\lpc_core\lpc_board\boards_8xx\nxp_lpcxpresso_824',
	r'-I..\..\..\..\..\..\software\lpc_core\lpc_board\board_common',
	r'-I..\..\..\..\..\..\software\CMSIS\CMSIS\Include',
	r'-DCORE_M0PLUS']

def file_parse(opt):
    from pycparserext.ext_c_parser import GnuCParser
    p = GnuCParser()
    ast = p.parse(opt.input,cpp_args=ARGV)
    ast.show()


#-------------------------------------------------------------------------------
##	parse_args -- parse command line arguments
#
##	\brief
#   Parse generate project arguments:
#
##	\param	input	options passed from command line
#-------------------------------------------------------------------------------
def parse_args():
	import argparse
	ap = argparse.ArgumentParser(description="NXP file processor")

	ap.add_argument("-i", "--input", default="test.ctags",
					help="Input file name (default: %(default)s)")

	if len(sys.argv) == 1:
		ap.print_help()
		sys.exit(1)
	return ap.parse_args()


#-------------------------------------------------------------------------------
#   main:
#   - Parse the arguments
#   - Parse the file
#-------------------------------------------------------------------------------
def main():
	options = parse_args()
	file_parse(options)
	return 0


#-------------------------------------------------------------------------------
#   Main processing
#-------------------------------------------------------------------------------
if __name__ == "__main__":
	sys.exit(main())

#
#   End: nxp_cpp.py
#
